package hos.thread.executor;

import hos.thread.RunnableJob;
import hos.thread.RunnableLife;
import hos.thread.ThreadOption;


/**
 * <p>Title: CallBackground </p>
 * <p>Description:  </p>
 * <p>Company: www.mapuni.com </p>
 *
 * @author : 蔡俊峰
 * @version : 1.0
 * @date : 2022/3/16 11:46
 */
public abstract class CallBackground<T> extends RunnableJob<T> {

    public CallBackground(ThreadOption.onBackgroundListener<T> onBackground) {
        super(onBackground);
        onStart(CallBackground.this::onStart);
        onCancel(CallBackground.this::onCancel);
        onCatch(CallBackground.this::onThrowable);
        onProgress(CallBackground.this::onProgress);
        onSuccess(CallBackground.this::onSuccess);
    }

    /**
     * 执行完成
     *
     * @param result 返回结果
     */
    public abstract void onSuccess(RunnableJob<T> runnableLife, T result);

    public void onStart(RunnableLife runnableLife) {

    }

    public void onCancel() {

    }

    public void onProgress(Double value) {

    }

    public void onThrowable(Throwable throwable, String threadName) {

    }
}
